package servlet;

import java.io.IOException;
import java.util.Objects;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebServlet(urlPatterns= {"/index.servlet"})
public class IndexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Cookie[] cookies=request.getCookies();
		boolean flag=false;
		if(cookies!=null&&cookies.length!=0) {
			for(int i=0,len=cookies.length;i<len;i++) {
				if(Objects.equals(cookies[i].getValue(),"www.blog.com"));
				flag=true;
				break;
			}
		}
		
		if(flag) {
			request.getRequestDispatcher("view/main.jsp").forward(request, response);
	}else {
		request.getRequestDispatcher("login.jsp").forward(request, response);
	}
}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
